Boxplots are convenient way of graphically depicting groups of numerical data through their quartiles. Box plots may also have lines extending vertically from the boxes (whiskers) indicating variability outside the upper and lower quartiles, hence the terms box-and-whisker plot and box-and-whisker diagram. Outliers may be plotted as individual points.
Let's see how we can create them with qplot and ggplot!
library(ggplot2)
df <- mtcars
head(df)
qplot(factor(cyl), mpg, data = mtcars, geom = "boxplot")
pl <- ggplot(mtcars, aes(factor(cyl), mpg))
pl + geom_boxplot()
pl + geom_boxplot() + coord_flip()
pl + geom_boxplot(aes(fill = factor(cyl)))
pl + geom_boxplot(fill = "grey", color = "blue")
That's it for the basics of creating boxplots in ggplot2!